﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lib.Listeners
{
    class CellSelectedListener : ICellSelectListener
    {
        IBoard b;
        IPiece selectedPiece = null;
        Coordenada selectedCell = null;
        public CellSelectedListener(IBoard b)
        {
            this.b = b;
        }
        public void Listen(Coordenada selectedCell)
        {
            if (selectedPiece == null)
            {
                this.selectedPiece = this.b.GetCell(selectedCell.X, selectedCell.Y).GetPiece();
                this.selectedCell = selectedCell;
                PythonMoves m = new PythonMoves();
            }
            else
            {
                if (this.b.GetCell(selectedCell.X, selectedCell.Y).HasPiece())
                {
                    this.b.GetCell(selectedCell.X, selectedCell.Y).RemovePiece();
                }
                this.b.GetCell(selectedCell.X, selectedCell.Y).AddPiece(this.selectedPiece);
                this.b.GetCell(this.selectedCell.X, this.selectedCell.Y).RemovePiece();
                this.selectedCell = null;
                this.selectedPiece = null;                
            }

        }
    }
}
